package com.dyb.recuitment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dyb.recuitment.entity.Resume;
import com.dyb.recuitment.entity.Shield;
import com.dyb.recuitment.mapper.ResumeMapper;
import com.dyb.recuitment.service.IResumeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 简历表 服务实现类
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-15
 */
@Service
public class ResumeServiceImpl extends ServiceImpl<ResumeMapper, Resume> implements IResumeService {

    @Autowired
    private ResumeMapper resumeMapper;

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public List<Resume> selectAllResume() {
        return resumeMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public Resume getById(Resume resume) {
        resume.setStatus(1);
        QueryWrapper<Resume> queryWrapper = new QueryWrapper<>(resume);
        List<Resume> result = resumeMapper.selectList(queryWrapper);
        if (result.size() > 0) {
            return result.get(0);
        }
        return null;
    }

    @Override
    public int add(Resume resume) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        resume.setCreateTime(localDateTime).setUpdateTime(localDateTime);
        return resumeMapper.insert(resume);
    }

    @Override
    public int update(Resume resume) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        resume.setUpdateTime(localDateTime);
        return resumeMapper.updateById(resume);
    }


    @Override
    public int delete(Resume resume) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        resume.setStatus(0).setUpdateTime(localDateTime);
        return resumeMapper.updateById(resume);
    }

    @Override
    public List<Resume> selectByCreateBy(Resume resume) {
        resume.setStatus(1);
        QueryWrapper<Resume> queryWrapper = new QueryWrapper<>(resume);
        return resumeMapper.selectList(queryWrapper);
    }


}
